<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>Picking List Print</title>
		<script src='${ctxPath}/assets/mui/js/jquery-1.11.3.js'></script>
	</head>
	<style>
		p{
			font-size: 9px;
			height: 2px;
		}
		.button{
			background-color: #A6A6A6; color: black; /* Green */
		    border: none;
		    color: white;
		    padding: 10px 32px;
		    text-align: center;
		    text-decoration: none;
		    display: inline-block;
		    font-size: 14px;
    	}
	</style>
	<body>
		<div style="width: 100%;">
			<button id="button" class="button" onclick="doPrint()">Print</button>
		</div>
		<div id="big" style="width: 100%;">
		</div>
		<script type="text/jscript">
			//通过URL 获取参数
			function GetQueryString(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
				var r = window.location.search.substr(1).match(reg);
				if(r != null) return unescape(r[2]);
				return null;
			};
			var ids = GetQueryString("ids");
			var arrids = [];
			arrids = ids.split(",");
			var getUnit = "${storageOutParam.getUnit}";
			var getLocation = "${storageOutParam.getLocation}";
			load();
			function load(){
				var big = $("#big");
				var storageOutmsg = '<div id="-title" style="width: 100%; height: 20px;text-align: center;">'+
										'<h5 style="height: 2px;">Shandong Xianfei Logistics Co., Ltd. Picking List</h5>'+
									'</div>'+
									'<div id="-title-l" style="width: 100%; height: 15px;">'+
										'<h6 style="float: left; width: 50%;height: 2px;">Receiving Unit: '+getUnit+'</h6>'+
										'<h6 style="float: right;width: 50%; text-align: right;height: 2px;">Receiving Address: '+getLocation+'</td>'+
									'</div>';
				big.append(storageOutmsg);
				for(var i = 0; i <arrids.length; i++){
					$.ajax({
					    url:'${ctxPath}/storageOut/getPrintstorageOut',
					    type:'post',
					    dataType:'json',
					    data:{"id":arrids[i]},
					    success:function(data){
					        if(data!=null){
							    var storageOuttitle = '<div id="order-title" style="width: 100%;height: 60px;margin-top: 40px;">'+
												'<div id="order-title-1" style="width: 100%;">'+
													'<p style="float: left; width: 26%;">Picking Order No.: '+data.storageOutNumber+'</p>'+
													'<p style="float: left; width: 24%;">Customer Order No.: '+data.customerNumber+'</p>'+
													'<p style="float: left; width: 24%;">Vehicle No.: '+data.privatecarCarnumbers+'</p>'+
													'<p style="float: right; width: 24%;">Transport No.: '+data.transportNumber+'</p>'+
												'</div>'+
												'<div id="order-title-2" style="width: 100%;">'+
													'<p style="float: left; width: 40%;">Customer Purchase Order No.: '+data.procurementNumber+'</p>'+
													'<p style="float: left; width: 24%;">Preparation Area: '+data.areanumber+'</p>'+
													'<p style="float: left; width: 24%;">Warehouse: '+data.storehouseName+'</p>'+
												'</div>'+
											'</div>';
								big.append(storageOuttitle);
								$.ajax({
									url:'${ctxPath}/storageOutDetailed/getPrintstorageOutDetailed',
									type:'post',
									dataType:'json',
									async:false,
									data:{"storageOutNumber":data.storageOutNumber},
									success:function(data){
										if(data.length>0){
											var ncont = 0.0;
											var vcont = 0.0;
											var storageOutdata = '<div id="order-date" style="width: 100%;height: auto;">'+
														'<table id="order-table" style="width: 100%; font-size: 9px;" border="1px solid" cellpadding="0" cellspacing="0">'+
															'<thead>'+
																'<th>Material Code</th>'+
																'<th>Material Description</th>'+
																'<th>Packaging</th>'+
																'<th>Specifications</th>'+
																'<th>Quantity</th>'+
																'<th>Volume</th>'+
																'<th>Batch</th>'+
																'<th>Location</th>'+
															'</thead>'+
															'<tbody>';
												$.each(data,function(key,value){
													ncont += value.storageNumber*1;
													vcont += value.storageVolume*1;
													storageOutdata += '<tr>'+
																'<td>'+value.storageGoodscode+'</td>'+
																'<td>'+value.storageGoodsname+', '+value.goodsNo+'</td>'+
																'<td>'+value.storagePacking+'</td>'+
																'<td>'+value.goodsSpecs+'</td>'+
																'<td>'+value.storageNumber+'</td>'+
																'<td>'+value.storageVolume+'</td>'+
																'<td>'+value.storageBatchnumber+'</td>'+
																'<td>'+value.storagePostionNumber+'</td>'+
															'</tr>';
												});
												storageOutdata += '<tr>'+
															'<td></td>'+
															'<td></td>'+
															'<td>Total:</td>'+
															'<td></td>'+
															'<td>'+Math.round(ncont * 100) / 100+'</td>'+
															'<td>'+Math.round(vcont * 100) / 100+'</td>'+
															'<td></td>'+
															'<td></td>'+
														'</tr>';
												storageOutdata += '</tbody>'+
														'</table>'+
													'</div>';
												big.append(storageOutdata);
										}else{
												alert("No picking list details found!");
										}
									},
									error:function(data){
										alert("Error querying picking list details!");
									}
								});
							}else{
								alert("No picking list found!");
							}
						},
						error: function(data){
							alert("Error querying picking list!");
						}
					});
				}
			};
			//打印
			function doPrint() {
			    bdhtml = window.document.body.innerHTML;
			    phtnl = window.document.getElementById("big").innerHTML;
			    window.document.body.innerHTML = phtnl; //Assign the specified content to be printed to big
			    window.print(); //Call the browser's print function to print the specified area
			    window.document.body.innerHTML=bdhtml; //Finally restore the page
			};
			//打印的回调
			var beforePrint = function() {
			    //Called before printing
			};
			var afterPrint = function() {
			    //Called after printing
			    $.ajax({
			        url:"${ctxPath}/storageOut/print",    //Requested URL address
			        dataType:"json",   //Return format as json
			        type:"post",   //Request method
			        success:function(req){
			            if(req){
			                var Indexs = parent.layer.getFrameIndex(window.name);
			                parent.layer.close(Indexs);
			            }
			        }
			    });
			};
			if (window.matchMedia) {
			    var mediaQueryList = window.matchMedia('print');
			    mediaQueryList.addListener(function(mql) {
			        if (mql.matches) {
			            beforePrint();
			        } else {
			            afterPrint();
			        }
			    });
			}
		</script>
	</body>
</html>